Support i64.mul_wide_s and i64.mul_wide_u from Wide Arithmetic proposal#8652
Support i64.mul_wide_s and i64.mul_wide_u from Wide Arithmetic proposal#8652stevenfontanella wants to merge 1 commit intomainfrom
Conversation
3ba6b06 to
80fe1b7
Compare
eb019af to
64dad92
Compare
3fabe33 to
60966ed
Compare
60966ed to
241a56b
Compare
| @@ -0,0 +1,89 @@ | |||
| // Copyright 2024 WebAssembly Community Group participants | |||
There was a problem hiding this comment.
| // Copyright 2024 WebAssembly Community Group participants | |
| // Copyright 2026 WebAssembly Community Group participants |
| @@ -0,0 +1,45 @@ | |||
| // Copyright 2024 WebAssembly Community Group participants | |||
There was a problem hiding this comment.
| // Copyright 2024 WebAssembly Community Group participants | |
| // Copyright 2026 WebAssembly Community Group participants |
| uint64_t cross = mulLowHigh + (mulLowLow >> 32); | ||
| uint64_t carry = cross >> 32; | ||
| cross = (cross & 0xffffffff) + mulHighLow; |
There was a problem hiding this comment.
It's not immediately obvious to me how cross corresponds to the explanatory comments below. It would be good to make sure the code directly follows from the comments.
It might also be helpful to start with a comment like result = (lhsHigh * 2^32 + lhsLow) * (rhsHigh * 2^32 + rhsLow) = lhsHigh * rhsHigh * 2^64 + lhsHigh * rhsLow * 2^32 + lhsLow * rhsHigh * 2^32 + lhsLow * rhsLow
|
|
||
| namespace detail { | ||
|
|
||
| Int128 mul_wide_s_fallback(uint64_t lhs, uint64_t rhs) { |
There was a problem hiding this comment.
It would be nice to have some comments explaining the math here, too.
| @@ -0,0 +1,95 @@ | |||
| // Copyright 2024 WebAssembly Community Group participants | |||
There was a problem hiding this comment.
| // Copyright 2024 WebAssembly Community Group participants | |
| // Copyright 2026 WebAssembly Community Group participants |
| INSTANTIATE_TEST_SUITE_P(Int128, | ||
| Int128MulWideSTest, | ||
| ::testing::Values(mul_wide_s, | ||
| detail::mul_wide_s_fallback)); |
There was a problem hiding this comment.
What does this do? I've never seen TEST_P before.
|
|
||
| int64_t maxInt = std::numeric_limits<int64_t>::max(); | ||
| // Fits in the lower half because the signed bit now goes in the upper half. | ||
| EXPECT_EQ(mul_s(maxInt, 2), (Int128{0, 0xfffffffffffffffeULL})); |
There was a problem hiding this comment.
It would be nice to show that reversing the order of operands doesn't change the results here and below.
Part of #8544. Unit tests were written by Gemini and double-checked against python with this script.
TODO: Move the existing 128 add/sub logic from the interpreter into int128.h.